home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1102 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: aril@cmt.lpr.mail.carel.fi (Ari Lukumies)
  3. Newsgroups: comp.lang.c,comp.lang.objective-c
  4. Subject: Re: Comma Delimited function wanted
  5. Date: Thu, 11 Jan 1996 13:19:43 GMT
  6. Organization: Carelcomp Forest Oy
  7. Message-ID: <4d3360$kg3@tahko.lpr.carel.fi>
  8. References: <4d1l42$mb6@voyager.Internex.NET>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. ian_stewart@nyro.com (Ian H. Stewart) wrote:
  13.  
  14. >Help with a comma delimited function needed.
  15.  
  16. >I did this once before, but I am blocked and can't
  17. >find the original source.
  18.  
  19. >Here is what I need to do:
  20.  
  21. >I have a buffer full of text.
  22.  
  23. >char buffer = "3740067099,914885AC2,P03,5000";
  24.  
  25. >I have four char vars to put this into.
  26.  
  27. >char field1[20], field2[20], field3[20], field4[20];
  28.  
  29. >What I want to do is get this as the end result.
  30.  
  31.  
  32. >field1 = 3740067099
  33. >field2 = 914885AC2
  34. >field3 = P03
  35. >field4 = 5000
  36.  
  37.  
  38. >Anyway, help is appreciated.
  39.  
  40. >ian
  41.  
  42. Try something like this:
  43.  
  44.     char    buffer[] = "1,2,3,4";    /* Just an example */
  45.     char    *p = buffer;        /* points to begin of buf */
  46.     char    field[4][20];
  47.     int    i, j;
  48.  
  49.     for (j = 0; j < 4; j++) {
  50.         memset(field[j], 0, sizeof(field[j]));    /* Initialize to zeros */
  51.         for (i = 0; i < sizeof(field[j]); i++, p++)
  52.             if (*p == ',' || !*p) {
  53.                 field[j][i] = '\0';
  54.                 break;
  55.             }
  56.             else
  57.                 field[j][i] = *p;
  58.     }
  59.  
  60. Later,
  61. AriL
  62.  
  63. All my opinions are mine and mine alone.
  64.  
  65.